<template>
	<view class="content">
		<view class="header text-C">共{{ examList.length }} 题</view>
		<view class="body">
			<view class="dis-flex-hsb">
				<view>单选题</view>
				<view>{{typeList.single.num}}</view>
			</view>
			<view class="border-line"></view>
			<view class="dis-flex-hsb">
				<view>抽取(单选题)</view>
				<view class="dis-flex-hsb">
					<text class="add-jian" @click="changeNum('single',0)">-</text>
					<input v-model="typeList.single.takeNum" :min="0" :max="typeList.single.num" class="add-num">
					<text class="add-jia" @click="changeNum('single',1)">+</text>
				</view>
			</view>
			<view class="border-line"></view>
			<view class="dis-flex-hsb">
				<view>多选题</view>
				<view>{{typeList.multi.num}}</view>
			</view>
			<view class="border-line"></view>
			<view class="dis-flex-hsb">
				<view>抽取(多选题)</view>
				<view class="dis-flex-hsb">
					<text class="add-jian" @click="changeNum('multi',0)">-</text>
					<input v-model="typeList.multi.takeNum" :min="0" :max="typeList.multi.num" class="add-num">
					<text class="add-jia" @click="changeNum('multi',1)">+</text>
				</view>
			</view>
			<view class="border-line"></view>
			<view class="dis-flex-hsb">
				<view>判断题</view>
				<view>{{typeList.judge.num}}</view>
			</view>
			<view class="border-line"></view>
			<view class="dis-flex-hsb">
				<view>抽取(判断题)</view>
				<view class="dis-flex-hsb">
					<text class="add-jian" @click="changeNum('judge',0)">-</text>
					<input v-model="typeList.judge.takeNum" :min="0" :max="typeList.judge.num" class="add-num">
					<text class="add-jia" @click="changeNum('judge',1)">+</text>
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="footer-btn bg-73a9fa color-ff" @click="onConfirm">确定</view>
		</view>
	</view>
</template>

<script>
	import {request,uploads,rectTo,navTo,showMsg} from "@/utils";
	export default {
		data() {
			return {
				paper_id:0,
				exam_id:0,
				type:0,
				examList:[],
				typeList:{
					single:{num:0,takeNum:0},
					multi:{num:0,takeNum:0},
					judge:{num:0,takeNum:0}
				}
			}
		},
		onLoad(options) {
			if(options.item){
				let item = JSON.parse(decodeURIComponent(options.item));
				console.log(item);
				if(item.paper_id){
					this.paper_id = item.paper_id;
				}
				if(item.exam_id){
					this.exam_id = item.exam_id;
				}
				if(item.type){
					this.type = item.type;
				}
				this.getList();
			}
		},
		methods: {
	async getList(){
		uni.showLoading({
			title:'数据加载中...'
		});
				let res = await request({
					method:'POST',
					data:{paper_id:this.paper_id,exam_id:this.exam_id,exam_type:4},
					url:"/appexam/randlist"
				});
				uni.hideLoading();
				console.log('exam rand getData',res);
				if(res.code){
					let msg = '请求失败';
					if(res?.msg && res.msg){
						msg = res.msg;
					}
					showMsg('this',{title:msg});
				}
				if(res?.data?.list){
					this.examList = res.data.list;
				}
				if(res?.data?.typelist){
					this.typeList = res.data.typelist;
				}
			},
			changeNum(type,tag){
				if(tag>0){
					this.typeList[type]['takeNum']++;
					if(this.typeList[type]['takeNum']>=this.typeList[type]['num']){
						this.typeList[type]['takeNum'] = this.typeList[type]['num'];
					}
				}else{
					this.typeList[type]['takeNum']--;
					if(this.typeList[type]['takeNum']<0){
						this.typeList[type]['takeNum'] = 0;
					}
				}
			},
			onConfirm(){
				let param = {
					paper_id:this.paper_id,
					exam_id:this.exam_id,
					typelist:JSON.stringify(this.typeList)
				};
				navTo("/pages/exam/randExam",param);
			}
		}
	}
</script>

<style>
	page{
		background-color: #f8f8f8;
	}
	.header{
		height: 40px;
		line-height: 40px;
		background-color: #fff;
	}
	.body{
		margin-top: 10px;
		margin-left: 20rpx;
		margin-right: 20rpx;
		padding: 20rpx;
		background-color: #fff;
		border-radius: 12rpx;
	}
	.border-line{
		width: 100%;
		height: 1rpx;
		margin: 10px 0;
		background-color: #ccc;
	}
	.add-jian{
		background-color: #ccc;
		border-radius: 4rpx;
		color: #000;
		padding: 3px 20rpx;
		font-size: 16;
	}
	.add-jia{
		background-color: #ddd;
		border-radius: 4rpx;
		color: #000;
		padding: 3px 20rpx;
		font-size: 16;
	}
	.add-num{
		width: 60rpx;
		padding: 2px 6rpx;
		margin: 0 20rpx;
		font-size: 14px;
		text-align: center;
	}
	.footer{
		margin-top: 20px;
		padding: 0 20rpx;
	}
	.footer-btn{
		height: 40px;
		line-height: 40px;
		border-radius: 20px;
		text-align: center;
	}
</style>